﻿using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HECore.ServiceFrame.Attributes
{
    /// <summary>
    /// 审计日志
    /// </summary>
    public class AuditedAttribute : TypeFilterAttribute
    {
        /// <summary>
        /// 审计日志
        /// </summary>
        public AuditedAttribute() : base(typeof(AuditedActionFilter)) { }
    }

    /// <summary>
    /// 审计日志
    /// </summary>
    public class AuditedActionFilter : IActionFilter
    {
        private readonly ILogger<AuditedActionFilter> _logger;

        /// <summary>
        /// 审计日志
        /// </summary>
        /// <param name="logger"></param>
        public AuditedActionFilter(ILogger<AuditedActionFilter> logger) { _logger = logger; }

        /// <summary>
        /// 审计日志
        /// </summary>
        /// <param name="context"></param>
        public void OnActionExecuted(ActionExecutedContext context) { }

        /// <summary>
        /// 审计日志
        /// </summary>
        /// <param name="context"></param>
        public void OnActionExecuting(ActionExecutingContext context) { _logger.LogTrace(context.HttpContext.Request.Path); }
    }
}
